<template>
    <div class="shop_car">
        <!-- 商品信息 -->
        <div class="mui-card" v-for="(item,i) in getcarlist" :key="item.id">
            <div class="mui-card-content" >
                <div class="mui-card-content-inner">
                    <!-- mt-switch 里有一个跟input一样得change事件，是否被选中 -->
                    <mt-switch v-model="$store.getters.getgoodsSelect[item.id]"
                       @change="selectChange(item.id,$store.getters.getgoodsSelect[item.id])" 
                    ></mt-switch>
                    <img :src ='item.thumb_path' alt="">
                    <div class="info">
                        <h3>{{item.title}}</h3>
                        <p>
                            <!-- 价格 -->
                            <span class="price">￥{{item.sell_price}}</span>
                            <Num :idcount="$store.getters.getgoodidc[item.id]" :goodsid="item.id"></Num>
                            <a href="#" @click.prevent="deldata(item.id,i)">
                                删除 
                            </a>

                        </p>
                    </div>
                </div>
            </div>
		</div>
        <!-- 计费 -->
        <div class="mui-card">
            <div class="mui-card-content">
                <div class="mui-card-content-inner jiesuan">
                    <div class="left">
                        <p>总计(不含运费)</p>
                        <p>已勾选商品 <span class="red">{{$store.getters.getgoodsCountAndmount.count}}</span>件,总价 
                        <span class="red">￥{{$store.getters.getgoodsCountAndmount.amount}}</span></p>
                    </div>
                    <mt-button type="danger">去结算</mt-button>
                </div>
            </div>
		</div>
        
    </div>
</template>
<script>
import Num from '../subcomponent/shopcar_num.vue'
export default {
    data(){
        return {
            getcarlist:[]
        }
    },
    created(){
        this.getshop()
    },
    methods:{
       
        getshop(){
             var listId = [];
            this.$store.state.car.forEach(item => listId.push(item.id))
            //如果购物车没货物
            if(listId.length===0){
                return;
            }
            this.$http.get("api/goods/getshopcarlist/"+listId.join(",")).then(result =>{
                if(result.body.status===0){
                    this.getcarlist = result.body.message
                }
            })
        },
        deldata(id,index){
            //首先得删除卡片渲染得那个数组 getcarlist:[]，让其没得渲染，
            // 其次要删除vuex里car对应得id
            this.getcarlist.splice(index,1);
            this.$store.commit('removeData',id)
        },
        // mt-swich按钮得打开关上
        selectChange(id,val){
            //console.log(id+"---"+val)
            this.$store.commit("selectChange",{id,selected:val})
            
            console.log(this.$router)
            console.log(this.$route)
            
        }
    },
    components:{
        Num
    }
}
</script>
<style lang="scss" scoped>
    .shop_car {
        .mui-card-content-inner {
            display:flex;
            align-items: center;
            h3 {
                font-size: 13px;
            }
            .price {
                color:red;
            }
            
        }
        .mui-card {
            background-color:#fff;
            img {
                width:60px;
                height:60px;
            }
        }
        .jiesuan{
            display: flex;
            justify-content: space-between;
            align-items: center;
            .red{
                color:red;
                font-size:16px;
                
            }
        }
    }
</style>